using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class GroupCardView : BasePage
	{
		private const string TAG = "GroupCardView";
		private Contact mConGroup;
		private string mStrGroupCardName;
		private List<Contact> mListContacts;
		private bool mBIsFirtTimeLoaded = true;
		private ApplicationBar mBar;
		internal Grid LayoutRoot;
		internal EmojiText txtPageTitle;
		internal StackPanel PeoplePanel;
		internal ScrollViewer scrollViewList;
		internal PeopleList AddPeopleList;
		internal Button btnStartChat;
		internal StackPanel ContentPanel;
		internal ListBox listBoxPeople;
		private bool _contentLoaded;
		public GroupCardView()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.GroupCardView_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.GroupCardView_Unloaded));
			base.set_ApplicationBar(this.GetApplicationBar());
		}
		private void GroupCardView_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private void GroupCardView_Loaded(object sender, RoutedEventArgs e)
		{
			if (this.mBIsFirtTimeLoaded)
			{
				this.mBIsFirtTimeLoaded = false;
				this.initDataSource();
				this.scrollViewList.set_Visibility(0);
				base.set_ApplicationBar(this.GetApplicationBar());
				this.setAppBarStyle(base.get_ApplicationBar());
			}
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("GroupCardView", "OnPageIn");
			if (object_0 != null && object_0.Length != 0)
			{
				if (object_0[0].GetType() == typeof(Contact))
				{
					this.mConGroup = (object_0[0] as Contact);
					this.mStrGroupCardName = this.mConGroup.strUsrName;
					if (!string.IsNullOrEmpty(this.mConGroup.strNickName) && this.mConGroup.strNickName != strings.ChatDefaultTopic)
					{
						this.txtPageTitle.Text = this.mConGroup.strNickName;
						return;
					}
					if (ToolFunction.checkIsLegalRemark(this.mConGroup.strRemark))
					{
						this.txtPageTitle.Text = this.mConGroup.strRemark;
						return;
					}
					this.txtPageTitle.Text = this.mConGroup.strNickName;
					return;
				}
			}
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("GroupCardView", "OnPageOut");
		}
		private void initDataSource()
		{
			this.AddPeopleList.SetChatRoomUsername(this.mStrGroupCardName);
		}
		private List<Contact> getDataByGroupName(string strGroupName)
		{
			if (string.IsNullOrEmpty(strGroupName))
			{
				return null;
			}
			return ChatRoomMgr.getChatRoomMemberContactList(strGroupName);
		}
		private void ContactListItem_ItemClick(object sender, object object_0)
		{
			if (sender != null && sender is ContactListItem)
			{
				ContactListItem contactListItem = sender as ContactListItem;
				ContactDetailViewForAll.GotoContactDitailView(strings.COM_ConList, strings.COM_ConDetail, contactListItem.ItemObject, ContactDetailFromType.FROM_MMCONTACT, false);
				return;
			}
		}
		private void btnStartChat_Click(object sender, RoutedEventArgs e)
		{
			ChatContainerPage.GoToChatPage(this, this.mStrGroupCardName, null, null, null);
		}
		public ApplicationBar GetApplicationBar()
		{
			if (this.mBar != null)
			{
				if (!this.mBar.get_IsVisible())
				{
					this.mBar.set_IsVisible(true);
				}
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			ApplicationBarIconButton applicationBarIconButton = new ApplicationBarIconButton(new Uri("/Resource/Img/ContactList/Ico_AppBar_SendMsg.png", 2));
			applicationBarIconButton.set_Text(strings.Con_FMsg_BtnGoChat);
			applicationBarIconButton.add_Click(new EventHandler(this.btnStartChatting_Click));
			this.mBar.get_Buttons().Add(applicationBarIconButton);
			this.setAppBarStyle(this.mBar);
			return this.mBar;
		}
		private void btnStartChatting_Click(object sender, EventArgs e)
		{
			ChatContainerPage.GoToChatPage(this, this.mStrGroupCardName, null, null, null);
		}
		private void btnRemark_Click(object sender, EventArgs e)
		{
			object[] array = new object[2];
			array[0] = new DelegateSetRemark(this.setRemarkName);
			string strNickName = this.mConGroup.strNickName;
			array[1] = strNickName;
			base.GoToPage("/Source/UI/Contact/ContactSetRemarkView.xaml", array, false);
		}
		private void btnDelete_Click(object sender, EventArgs e)
		{
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Con_FMsg_MsgDelTitle, strings.Con_FMsg_MsgDelCon, true, strings.COM_Del, strings.COM_Cancel);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.OnDeleteContactHandler);
		}
		private void OnDeleteContactHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				Log.smethod_5("GroupCardView", "before del mContactDitailViewArgs.mContact.nFlags = " + this.mConGroup.nFlags);
				ContactMgr.operationSetContact(this.mConGroup, false);
				Log.smethod_5("GroupCardView", "after del mContactDitailViewArgs.mContact.nFlags = " + this.mConGroup.nFlags);
				ServiceCenter.sceneNewSync.doScene(4, syncScene.MM_NEWSYNC_SCENE_OTHER);
				base.GoBack();
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		private void setRemarkName(string strNewRemark)
		{
			if (this.mConGroup == null)
			{
				return;
			}
			if (this.mConGroup.strNickName == strNewRemark)
			{
				return;
			}
			this.mConGroup.strNickName = strNewRemark;
			this.mConGroup.strPYInitial = SortStringsByAlpha.ConvertStringToPinyinInitial(strNewRemark);
			this.mConGroup.strQuanPin = GetPinYin.ConvertStrToQuanPin(strNewRemark);
			ContactMgr.operationModContact(this.mConGroup);
			MessageBoxManager.ShowToast(strings.Con_FMsg_MsgRemarkSucc, 2500, null, false);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Contact/GroupCardView.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.txtPageTitle = (EmojiText)base.FindName("txtPageTitle");
			this.PeoplePanel = (StackPanel)base.FindName("PeoplePanel");
			this.scrollViewList = (ScrollViewer)base.FindName("scrollViewList");
			this.AddPeopleList = (PeopleList)base.FindName("AddPeopleList");
			this.btnStartChat = (Button)base.FindName("btnStartChat");
			this.ContentPanel = (StackPanel)base.FindName("ContentPanel");
			this.listBoxPeople = (ListBox)base.FindName("listBoxPeople");
		}
	}
}
